package com.example.sqldemo.type;

import java.util.ArrayList;
import java.util.List;

public class Test {

    public void m1(List<? extends BaseStudent> list){
//        list.add(new StudentFirst());
//        list.add(new StudentSecond());
//        list.add(new BaseStudent());
        System.out.println("m1 方法: "+list.toString());
    }

    public void m2(List<? super BaseStudent> list){
        list.add(new StudentFirst());
        list.add(new StudentSecond());
        list.add(new BaseStudent());
        System.out.println("m2 方法: "+list.toString());
    }


    public static void main(String[] args) {
        Test test = new Test();
        List<StudentFirst> studentFirsts = new ArrayList<>();
        studentFirsts.add(new StudentFirst("哈哈1"));
        List<StudentSecond> studentSeconds = new ArrayList<>();
        studentSeconds.add(new StudentSecond("哈哈2"));
        List<BaseStudent> baseStudents = new ArrayList<>();
        baseStudents.add(new BaseStudent("BaseStudent 西安"));
        test.m1(studentFirsts); // 子类
        test.m1(studentSeconds); // 子类
        test.m1(baseStudents); // 本身
        // ==================================================
        List<BaseModel> baseModels = new ArrayList<>();
        baseModels.add(new BaseModel("baseModel"));
        test.m2(baseStudents); // 本身
        test.m2(baseModels);   // 父类

    }
}
